#include"chess.h"
#include<stdio.h>
#define WIN 5
void Chess::PrintChess()
{
  cout << "   ";
  for(int i = 0;i<_col;i++)
  {
    printf(" %-2d ",i+1);
  }
  cout << endl;
  for(int j = 0;j < ROW;j++)
  {
    cout << "  ";
    cout << "|";
    for(int i = 0;i < COL;i++)
    {
      cout << "---|";
    }
    cout << endl;
    printf("%-2d",j+1);
    cout << "|";
    for(int i = 0;i < COL;i++)
    {
      cout << " " << arr[j][i] << " |";
    }
    cout << endl;
  }
}
bool Chess::IsWin(char a,int row,int col)
{
  int iswin = 1;
  int i = 1;
  while(i < 5 && row - i >= 0)
  {
    if(arr[row-i][col] == a)
    {
      iswin++;
    }
    i++;
  }
  i = 1;
  while(i < 5 && row + i < _row)
  {
    if(arr[row+i][col] == a)
    {
      iswin++;
    }
    i++;
  }
  i = 1;
  if(iswin == WIN)
  { 
    return true;
  }
  

  iswin = 1;
  i = 1;
  while(i<5 && col - i >= 0)
  {
    if(arr[row][col-i] == a)
    {
      iswin++;
    }
    i++;
  }
  i = 1;
  while(i<5 && col + i < _col)
  {
    if(arr[row][col+i] == a)
    {
      iswin++;
    }
    i++;
  }
  if(iswin == WIN)
  {
    return true;
  }


  iswin = 1;
  i = 1;
  while(i<5 && col - i >= 0 && row + i < _row)
  {
    if(arr[row+i][col-i] == a)
    {
      iswin++;
    }
    i++;
  }
  i = 1;
  while(i<5 && col + i <= _col && row - i >= 0)
  {
    if(arr[row-i][col+i] == a)
    {
      iswin++;
    }
    i++;
  }
  if(iswin == WIN)
  {
    return true;
  } 


  
iswin = 1;
i = 1;
while(i<5 && col - i >= 0 && row - i >= 0)
{
      if(arr[row-i][col-i] == a)
      {
        iswin++;
      }
      i++;
}
    i = 1;
    while(i<5 && col + i <= _col && row + i <= _row)
    {
      if(arr[row+i][col+i] == a)
      {
        iswin++;
      }
      i++;
    }
    if(iswin == WIN)
    {
      return true;
    } 
   

  return false;
}
